package com.demo.common;

/**
 * 标准HTTP错误类型枚举
 */
public enum HttpErrorType {
    BAD_REQUEST(400, "Bad Request"),
    UNAUTHORIZED(401, "Unauthorized"),
    FORBIDDEN(403, "Forbidden"),
    NOT_FOUND(404, "Data Not Found"),
    METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
    UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
    TOO_MANY_REQUESTS(429, "Rate Limit Exceeded"),
    INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
    BAD_GATEWAY(502, "Bad Gateway"),
    SERVICE_UNAVAILABLE(503, "Service Unavailable"),
    GATEWAY_TIMEOUT(504, "Gateway Timeout");

    private final int statusCode;
    private final String description;

    HttpErrorType(int statusCode, String description) {
        this.statusCode = statusCode;
        this.description = description;
    }

    // Getters
    public int getStatusCode() {
        return statusCode;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据状态码查找枚举
     */
    public static HttpErrorType findByStatusCode(int statusCode) {
        for (HttpErrorType type : values()) {
            if (type.statusCode == statusCode) {
                return type;
            }
        }
        return INTERNAL_SERVER_ERROR; // 默认返回500
    }
}